Skip to content

fix(openai-agents): Resolve agent from bindings for openai-agents >= 0.14#6102

Merged
ericapisani merged 1 commit intomasterfrom
py-2382-update-openai-agents-patches
Apr 21, 2026
Merged

fix(openai-agents): Resolve agent from bindings for openai-agents >= 0.14#6102
ericapisani merged 1 commit intomasterfrom
py-2382-update-openai-agents-patches

Conversation

@ericapisani
Copy link
Copy Markdown
Member

@ericapisani ericapisani commented Apr 20, 2026

Update the openai-agents integration's run-loop patches to resolve the current agent from the new AgentBindings dataclass introduced in openai-agents 0.14, falling back to the pre-0.14 agent kwarg.

Prior to 0.14, run_single_turn, run_single_turn_streamed, execute_handoffs, and execute_final_output all received the current agent as agent=.... In 0.14 the library refactored these to pass bindings: AgentBindings (carrying public_agent and execution_agent) to the run_single_turn* functions and renamed the agent kwarg to public_agent on the execute_* functions. Our patches still called kwargs.get("agent"), which returned None — so _maybe_start_agent_span short-circuited and no invoke_agent span was ever created. Every test_agent_invocation_span* parametrization failed on the openai_agents-latest suite with not enough values to unpack (expected 2, got 1).

public_agent is used rather than execution_agent because it's the user-facing identity the library itself uses for lifecycle hooks (on_agent_start, on_llm_start), streamed_result.current_agent, and RunItem.agent fields. The two only diverge in sandbox execution (agents/sandbox/runtime.py), where execution_agent is a cloned sandbox-prepared agent — using that would produce unstable span names that don't match what users see from the library's own callbacks.

Verified locally against py3.14-openai_agents-latest (bindings path) and py3.14-openai_agents-v0.8.4 (legacy kwarg fallback path).

Refs PY-2382
Fixes #6101

…= 0.14

openai-agents 0.14 refactored its run loop to pass an `AgentBindings`
dataclass (with `public_agent` and `execution_agent` fields) instead of
a raw `agent` kwarg to `run_single_turn` / `run_single_turn_streamed`,
and renamed the `agent` kwarg to `public_agent` on `execute_handoffs` /
`execute_final_output`. As a result, the integration's `kwargs.get("agent")`
returned `None`, no `invoke_agent` span was created, and every
`test_agent_invocation_span*` case failed.

Resolve the agent from `bindings.public_agent` (or the `public_agent`
kwarg) with a fallback to the pre-0.14 `agent` kwarg so older pinned
versions remain supported. `public_agent` is the user-facing identity
the library itself uses for hooks and stream events, which keeps span
names stable across sandbox-prepared execution agents.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@linear-code
Copy link
Copy Markdown

linear-code bot commented Apr 20, 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 20, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (ci) Cancel in-progress PR workflows on new commit push by joshuarli in #5994
  • Add db.driver.name spans to database integrations by ericapisani in #6082

Bug Fixes 🐛

  • (google_genai) Redact binary data in inline_data and fix multi-part message extraction by ericapisani in #5977
  • (grpc) Add isolation_scope to async server interceptor by robinvd in #5940
  • (openai-agents) Resolve agent from bindings for openai-agents >= 0.14 by ericapisani in #6102
  • (profiler) Stop nulling buffer on teardown by ericapisani in #6075

Internal Changes 🔧

  • (celery) Remove unused NoOpMgr from utils by sentrivana in #6078
  • (ci) Update outdated pinned action version comments by JoshuaMoelans in #6088
  • (pydantic-ai) Remove dead Model.request patch by alexander-alderman-webb in #5956
  • (tests) Replace deprecated enable_tracingwith traces_sample_rate by sentrivana in #6077
  • Set explicit base-branch for codecov action by ericapisani in #5992

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 20, 2026

Codecov Results 📊

142 passed | Total: 142 | Pass Rate: 100% | Execution Time: 21.27s

All tests are passing successfully.

❌ Patch coverage is 0.00%. Project has 14156 uncovered lines.

Files with missing lines (1)
File Patch % Lines
agent_run.py 0.00% ⚠️ 98 Missing

Generated by Codecov Action

@ericapisani ericapisani marked this pull request as ready for review April 20, 2026 13:08
@ericapisani ericapisani requested a review from a team as a code owner April 20, 2026 13:08
Copy link
Copy Markdown
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@ericapisani ericapisani merged commit 34111be into master Apr 21, 2026
160 checks passed
@ericapisani ericapisani deleted the py-2382-update-openai-agents-patches branch April 21, 2026 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update patches in openai-agents due to introduction of AgentBindings

2 participants